import httpRequest from 'http.js'
import { config } from 'config.js'

let axios = new httpRequest()

const remove_undefined_props = (obj) => {
  for (const key in obj) {
    if (Object.hasOwnProperty.call(obj, key)) {
      const elm = obj[key];
      if (elm && elm.trim) {
        obj[key] = elm.trim();
      }
      if (elm === '' || elm === null || elm === undefined) {
        delete obj[key];
      }
    }
  }

  return obj;
}

const axios_base_get = (_url, req, _loading, handleError) => {
  req = remove_undefined_props(req);
  return axios.request('get', config.baseUrl + _url, req, _loading, handleError)
}

const axios_base_post = (_url, req, _loading, handleError) => {
  req = remove_undefined_props(req);
  return axios.request('post', config.baseUrl + _url, req, _loading, handleError)
}




export {
  axios_base_get,
  axios_base_post,
}
